package main

import (
	"duoke/boot"
	"duoke/middleware"
	"duoke/router"
	"duoke/service/task"
	"duoke/utils/yaml"
	"duoke/websocket"
	"fmt"
	"github.com/gin-gonic/gin"
	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
	_ "github.com/gogf/gf/contrib/nosql/redis/v2"
	"github.com/gogf/gf/v2/os/gctx"
)

func main() {
	// 部署模式
	gin.SetMode(gin.ReleaseMode)
	config := yaml.GetConfig()
	// 启动webman
	boot.RunWebman()
	// 启动初始化
	boot.Init()
	// 加载路由
	r := gin.Default()
	r.Use(middleware.GlobalErrorHandler())
	r.Use(middleware.Cors())
	r.Use(middleware.Init())
	err := r.SetTrustedProxies(nil)
	if err != nil {
		return
	}
	// 加载静态资源
	r.Static("/resource", "./public/resource")
	r.Static("/storage", "./public/storage")
	r.Static("/static", "./public/static")
	// 加载路由
	router.LoadAdmin(r)
	router.LoadConsole(r)
	router.LoadMp(r)
	router.LoadStaff(r)
	router.LoadComm(r)
	router.LoadYoga(r)
	websocket.StartWebSocket(gctx.New())
	router.LoadWebsocket(r)
	// 授权验证
	// task.CheckAuthorizeInit()
	// 定时器执行
	task.Init()
	// 运行程序
	fmt.Println("Local: http://127.0.0.1:" + config.Server.Port)
	_ = r.Run(":" + config.Server.Port)
}
